package com.example.project;

import com.example.project.model.Valoracion;
import com.example.service.ValoracionsParcelable;

import android.os.Bundle;
import android.os.Message;
import android.os.RemoteException;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RatingBar;

public class FormulariValoracions_IntroDades extends Activity {


	EditText coment;
	RatingBar rat;
	Button ok;
	Button clean;
	String comentario;
	String nota;
	String id;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_formulari_valoracions__intro_dades);
		
		coment=(EditText) findViewById(R.id.editText1);
		rat=(RatingBar) findViewById(R.id.ratingBarValForm);
		ok=(Button) findViewById(R.id.button2);
		id=getIntent().getExtras().getString("com.example.project.parcelable.id");
		
			ok.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				comentario=coment.getText().toString();
				nota=String.valueOf(rat.getRating());
		
				Valoracion val = new Valoracion();
				val.setComentario(comentario);
				val.setNota(nota);
				val.setIdRestaurante(Integer.parseInt(id));
		
				ValoracionsParcelable vp = new ValoracionsParcelable(0,"user",val);
				Bundle b = new Bundle();
				b.putParcelable("ValoracionParcelable",vp);
				Message msg = Message.obtain(null, DateBaseService.MSG_REGISTER_RECOMENDATION, 0, 0);
				msg.setData(b);
				try {
					MainActivity.mService.send(msg);
				} catch (RemoteException e) {
					e.printStackTrace();
				}

				Intent a = new Intent(v.getContext(), Project_Menu.class);
				v.getContext().startActivity(a);
			}
			});

	}
		

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(
				R.menu.activity_formulari_valoracions__intro_dades, menu);
		return true;
		
	}

}
